home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / softwareproperties / ppa.py < prev    next >
Text File  |  2009-09-07  |  3KB  |  89 lines

  1. #  software-properties PPA support
  2. #
  3. #  Copyright (c) 2004-2009 Canonical Ltd.
  4. #
  5. #  Author: Michael Vogt <mvo@debian.org>
  6. #
  7. #  This program is free software; you can redistribute it and/or
  8. #  modify it under the terms of the GNU General Public License as
  9. #  published by the Free Software Foundation; either version 2 of the
  10. #  License, or (at your option) any later version.
  11. #
  12. #  This program is distributed in the hope that it will be useful,
  13. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #  GNU General Public License for more details.
  16. #
  17. #  You should have received a copy of the GNU General Public License
  18. #  along with this program; if not, write to the Free Software
  19. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  20. #  USA
  21.  
  22. from threading import Thread
  23. from urllib2 import urlopen, Request, URLError
  24. import re
  25. import subprocess
  26. import apt_pkg
  27. from urlparse import urlparse
  28.  
  29. def expand_ppa_line(abrev, distro_codename):
  30.     """Convert a abreved ppa name to a sources.list line
  31.     Takes a string like 'ppa:$name' and returns a 'deb ...' line
  32.     """
  33.     # leave non-ppa: lines unchanged
  34.     if not abrev.startswith("ppa:"):
  35.         return (abrev, None)
  36.     # FIXME: add support for dependency PPAs too (once we can get them
  37.     #        via some sort of API, see LP #385129)
  38.     abrev = abrev.split(":")[1]
  39.     ppa_owner = abrev.split("/")[0]
  40.     try:
  41.         ppa_name = abrev.split("/")[1]
  42.     except IndexError, e:
  43.         ppa_name = "ppa"
  44.     sourceslistd = apt_pkg.Config.FindDir("Dir::Etc::sourceparts")
  45.     line = "deb http://ppa.launchpad.net/%s/%s/ubuntu %s main" % (
  46.         ppa_owner, ppa_name, distro_codename)
  47.     file = "%s/%s-%s-%s.list" % (
  48.         sourceslistd, ppa_owner, ppa_name, distro_codename)
  49.     return (line, file)
  50.  
  51.  
  52. class AddPPASigningKeyThread(Thread):
  53.     " thread class for adding the signing key in the background "
  54.  
  55.     def __init__(self, ppa_path):
  56.         Thread.__init__(self)
  57.         self.ppa_path = ppa_path
  58.         
  59.     def run(self):
  60.         self.add_ppa_signing_key(self.ppa_path)
  61.         
  62.     def add_ppa_signing_key(self, ppa_path):
  63.         """Query and add the corresponding PPA signing key.
  64.         
  65.         The signing key fingerprint is obtained from the Launchpad PPA page,
  66.         via a secure channel, so it can be trusted.
  67.         """
  68.         owner_name, ppa_name, distro = ppa_path[1:].split('/')
  69.         lp_url = ('https://launchpad.net/api/beta/~%s/+archive/%s' % (
  70.             owner_name, ppa_name))
  71.         try:
  72.             # we ask for a JSON structure from lp_page, we could use
  73.             # simplejson, but the format is simple enough for the regexp
  74.             req =  Request(lp_url)
  75.             req.add_header("Accept","application/json")
  76.             lp_page = urlopen(req).read()
  77.             #print lp_page
  78.             signing_key_fingerprint = re.findall(
  79.                 '\"signing_key_fingerprint\": \"(\w*)\"', lp_page)[0]
  80.             # FIXME: this needs to go - elmo says the keyserver will not handle
  81.             #        the load
  82.             subprocess.call(
  83.                 ["apt-key", "adv", "--keyserver", "keyserver.ubuntu.com",
  84.                  "--recv", signing_key_fingerprint])
  85.         except URLError, e:
  86.             print e
  87.  
  88.  
  89.